package com.health.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.health.R;
import com.health.tools.GlobalContsJTYS;
import com.health.viewscontrols.NovaApplication;

public class UpDataMenuGridAdapter2 extends BaseAdapter {
    private int[] imgs;
    private String[] names;
    private Context mContext;
    // 0"系统设置", 1"蓝牙设备绑定",2"数据上传", 3"综合统计"

    public UpDataMenuGridAdapter2(Context mContext, String admin) {
        this.mContext = mContext;
        if (GlobalContsJTYS.MENU_UPLOAD.equals(admin)) {
            if(NovaApplication.isBoolean_xiaoZhan()){
                imgs = new int[]{R.drawable.upload, R.drawable.upload,R.drawable.upload};
                names = new String[] { "资料数据上传","测量数据上传","数据上传慢病" };
            }else{
                imgs = new int[]{R.drawable.upload, R.drawable.upload};
                names = new String[] { "资料数据上传","测量数据上传" };

            }

        } else if (GlobalContsJTYS.MENU_DOWNLOAD.equals(admin)) {
            imgs = new int[]{R.drawable.download};//, R.drawable.download
            names = new String[]{"签约服务项目包"};//, "家庭签约用户"

        } else if (GlobalContsJTYS.MENU_SYNCHRONIZATION.equals(admin)) {
            imgs = new int[]{R.drawable.download, R.drawable.download, R.drawable.download,R.drawable.download};
//            names = new String[]{"更新医院及医生信息", "同步医院健康档案","家医签约服务包","高血压随访数据下载","糖尿病随访数据下载"};//,"更改行政区"
            names = new String[]{"更新医院及医生信息", "同步医院健康档案", "家医签约服务包","药品库"};//,"更改行政区"
        }
    }

    @Override
    public int getCount() {
        return imgs.length;
    }

    @Override
    public Object getItem(int position) {
        return imgs[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder vh;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.updata_menu_griditem, null);
            vh = new ViewHolder();
            int drawableID = imgs[position];
            String name = names[position];
            findView(vh, convertView, drawableID, name);
            convertView.setTag(R.id.TAG_VIEWHOLDER, vh);
        } else{
            vh = (ViewHolder) convertView.getTag(R.id.TAG_VIEWHOLDER);
        }
        setData(vh, convertView, position);
        return convertView;
    }

    /**
     * 赋值
     *
     * @param h
     * @param v
     * @param position
     * @author 王婷婷
     * @date 2015年12月3日 上午10:24:28
     */
    private void setData(ViewHolder h, View v, int position) {
    }

    private void findView(ViewHolder h, View v, int drawableID, String name) {
        h.img = (LinearLayout) v.findViewById(R.id.norm_img);
        h.nameText = (TextView) v.findViewById(R.id.norm_name);

//        h.img.setImageResource(drawableID);
        h.nameText.setText(name);
    }

    private static class ViewHolder {
        LinearLayout img;
        TextView nameText;
    }
}
